package com.zk.shop.servlet.user;

import com.zk.shop.entity.User;
import com.zk.shop.service.Impl.UserServiceImpl;
import com.zk.shop.service.UserService;
import com.zk.shop.util.MD5Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName Register
 * @Description TODO
 * @Author 来永刚
 * @Date 2019/9/30 0030下午 5:00
 * @Version 1.0
 **/
@WebServlet("/user/RegisterServlet")
public class RegisterServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String userpwd1 = req.getParameter("userpwd");
        String userpwd = MD5Util.md5(userpwd1);//加密
        String usertel = req.getParameter("usertel");
        String email = req.getParameter("email");
        User user  = new User(username,userpwd,usertel,email);
        UserService userService = new UserServiceImpl();
        int i = userService.register(user);
        if (i>0) {
            resp.sendRedirect("../login.html");
        } else {
            resp.sendRedirect("register.html");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
